Repository navigation
fix(clangd): attach document version to publishDiagnostics - #10
Conversation
ArcsinX
left a comment
There was a problem hiding this comment.
Thank you for the PR! Here is a detailed review. Overall, fixing document version propagation on publishDiagnostics is a great improvement. However, there are several issues and edge cases around URI canonicalization, version preservation on failed edits, API backward compatibility, and test assertions that should be addressed.
6de8f40 to
1e567b5
Compare
DrSergei
left a comment
There was a problem hiding this comment.
- Low — clangd/PseudoModule.cpp:245-251: failed didChange still calls clearDiagnosticsFor(...) even when wantDiagnostics=false, contradicting the commit's goal of honoring the flag. Edge case (unapplanable edit + flag off); arguably safe since the draft is gone.
- Informational — clangd/PseudoModule.cpp:183-197: the non-numeric elog/nullopt branch in decodeVersion is unreachable via updateDraft (mirrors upstream defensive code). No change needed.
- Test note — test_lsp.py:130-132: syntax_error_versions1 only captures the publish it breaks on, so it doesn't verify all syntax-error publishes carry version 1. Not a correctness bug.
Overall, LGTM
publishDiagnosticsFor set PublishDiagnosticsParams::version only when llvm::to_integer failed, so numeric versions were dropped and non-numeric strings were sent as 0. Clients need the version to discard diagnostics computed for an older text state. Pass the version DraftStore assigned to the draft straight through as std::optional<int64_t>, which removes the inverted check. Like ClangdLSPServer, publish the synthesized draft version when the client omits one. updateDraft now takes and returns the integer version, so the module has a single version representation. Also clear published diagnostics when an incremental change fails to apply and the draft is dropped, tagged with the rejected edit's version, and honor wantDiagnostics=false on didChange. The clear ignores wantDiagnostics, since without a draft nothing would replace those diagnostics. Publishing and clearing share one notification builder that uses the canonical file URI. Validation: PseudoModuleTests (77), ClangPseudoTests (46) and check-clang-pseudo (153) pass; test_lsp.py passes against the CI clangd build and fails with the unfixed plugin. Fixes #5
1e567b5 to
1d0e884
Compare
|
@DrSergei, on your three notes (addressed in 1d0e884):
Also in this push, with no behavior change: publishing and clearing go through one private Local checks: PseudoModuleTests 77/77, ClangPseudoTests 46/46, |
ArcsinX
left a comment
There was a problem hiding this comment.
LGTM! All comments have been cleanly addressed:
- Restored default
Version = std::nulloptacrossupdateDraftandpublishDiagnosticsFor. - Consolidated diagnostics dispatch and URI canonicalization via
sendDiagnostics, ensuring consistent canonical URIs for bothpublishDiagnosticsForandclearDiagnosticsFor. - Tagged cleared diagnostics on failed edits with the rejected edit's version.
- Resolved object lifetime order in
PseudoModuleLSPTestand returned copied JSON objects inpublished(). - Extended
test_lsp.pywith end-to-enddidChangeversion verification andwantDiagnostics: falsesuppression checks.
All tests (77/77 PseudoModuleTests and test_lsp.py) pass.
What
publishDiagnosticsForattached the document version only whenllvm::to_integerfailed (inverted check). Numeric versions were never sent, and a non-numeric one would have arrived asversion: 0. Without the version, clients can't drop diagnostics computed for an older text state, so a slow parse of an earlier edit can overwrite newer diagnostics while typing.Changes
std::optional<int64_t>instead of round-tripping it through a string. This removes the inverted check.DraftStoreassigns, asClangdLSPServerdoes.updateDraftnow takes and returns the integer version, so the module has one version representation.didClose) uses the canonical file URI, as publishing does.wantDiagnostics: falseondidChange.forceRebuildneeds no handling because every publish is a fresh parse.wantDiagnosticsbehavior.Tests
PseudoModuleLSPTestfixture inPseudoModuleTests. It records outgoing notifications and covers explicit versions plusdidClose, synthesized versions, failed changes clearing diagnostics, andwantDiagnostics: false.test_lsp.pyasserts that the syntax-error diagnostics are published for version 1 ondidOpen, for version 2 after adidChange, thatwantDiagnostics: falseskips publishing, and that an omitted version is synthesized.Verification
check-clang-pseudo152/152.test_lsp.pyagainst the clangd from the latestmainCI artifact (llvmaabe42e):Expected syntax error diagnostics published for version 1, got [None].Fixes #5